export default {
    data() {
        return {
            tableData: [],
            count: 0,
            page: 1,
            limit: 10,
            user_id: 0,
            keys: '',
            dialogVisible: false,
            member_remarks: '',
            member_id: 0,
            label: [{
                text: '全部',
                name: 'first'
            }, {
                text: '已授权用户',
                name: 'second'
            }, {
                text: '未授权用户',
                name: 'third'
            }],
            type:0,
        }
    },
    //进入页面加载
    mounted: function () {
        var that = this;
        //在缓存中获取值
        that.user_name = sessionStorage.getItem("user_name");
        that.user_id = sessionStorage.getItem("user_id");
        that.token = sessionStorage.getItem("access-token");
        if ((!that.token) || (!that.user_id) || (!that.user_name)) {
            that.$router.push('/login');
        }
        //请求员工列表
        that.getUser(that.pageNum,that.limit);
    },

    methods: {

        /**
         * 筛选
         */
        checkStatus:function (e) {
            let that = this;
            if(e === 'first') {
                that.type = 0;
            }
            if(e === 'second') {
                that.type = 1;
            }
            if(e === 'third') {
                that.type = 2;
            }
            that.getUser();
        },

        /**
         * 关键字筛选
         */
        search:function () {
            let that = this;
            that.getUser();
        },

        /**
         * 用户列表
         */
        getUser: function () {
            var that = this;
            //初始化数据
            that.tableData = [];
            that.count = 0;
            var formData = {};
            formData.token = that.token;
            formData.is_certification = that.type;

            if(that.keys !== ''){
                formData.nikmobie = that.keys;
            }
            //请求登陆接口
            that.$http.post(that.adminApi.api_url + "/api/userman/index",formData , {
                emulateJSON: true
            }).then(
                function (res) {
                    // 处理成功的结果
                    if (res.body.list.data) {
                        for (var i in res.body.list.data) {
                            that.tableData.push({
                                sort: Number(i)+1,
                                id: res.body.list.data[i].id,
                                uid: "<div style='color: #000fff'>" + res.body.list.data[i].user_no + "</div>",
                                grade: res.body.list.data[i].user_level_name,
                                nickname: res.body.list.data[i].nickname,
                                is_certification: res.body.list.data[i].is_certification,
                                is_zrd: res.body.list.data[i].is_zrd,
                                real_name: res.body.list.data[i].real_name,
                                gender: res.body.list.data[i].gender,
                                birth: res.body.list.data[i].birthday,
                                create_time: res.body.list.data[i].timestamp,
                                rday: res.body.list.data[i].daynum,
                                order_success_count: res.body.list.data[i].order_success_count,
                                total_pay: res.body.list.data[i].total_pay,
                                praise_count: res.body.list.data[i].praise_count,
                                review_count: res.body.list.data[i].review_count,
                                bad_count: res.body.list.data[i].bad_count,
                            });
                        }
                        that.count = res.body.count;
                    }
                },
                function () {
                    // 处理失败的结果
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ '处理异常' }`
                    });
                });
        },

        //下一页
        handleCurrentChange: function (currentPage) {
            var that = this;
            that.page = currentPage;
        },

        //搜索
        search: function () {
            var that = this;
            that.key = that.user_mobile;
            that.getUser();
        },

        /**
         * 解除实名验证
         */
        relieve: function (e) {
            var that = this;
            that.$confirm('是否确定解除该用户的实名认证?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                that.doDelete(e);
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        //执行删除
        doDelete: function (e) {
            var that = this;
            //请求登陆接口
            that.$http.post(that.adminApi.api_url + "/api/userman/relieve_auth", {
                token: that.token,
                id: e
            }, {
                emulateJSON: true
            }).then(
                function (res) {
                    // 处理成功的结果
                    that.$message({
                        type: 'success',
                        message: `操作提示: ${ '解除成功' }`
                    });
                    that.getUser();
                },
                function () {
                    // 处理失败的结果
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ '处理异常' }`
                    });
                });
        },

        /**
         * 添加备注
         */
        showTable: function (e) {
            let that = this;
            that.dialogVisible = true;
            that.member_id = e;
        },

        /**
         * 关闭弹窗
         */
        close_table: function () {
            let that = this;
            that.dialogVisible = false;
        },

        /**
         * 确定添加备注
         */
        confirm: function () {
            let that = this;
            if (that.member_remarks === '') {
                // 处理失败的结果
                that.$message({
                    type: 'error',
                    message: `操作提示: ${ '备注不能为空' }`
                });
            }
            //请求登陆接口
            that.$http.post(that.adminApi.api_url + "/api/userman/addremarks", {
                token: that.token,
                id: that.member_id,
                remarks: that.member_remarks
            }, {
                emulateJSON: true
            }).then(
                function (res) {
                    // 处理成功的结果
                    that.$message({
                        type: 'success',
                        message: `操作提示: ${ '添加成功' }`
                    });
                    that.dialogVisible = false;
                },
                function () {
                    // 处理失败的结果
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ '处理异常' }`
                    });
                });
        },

        /**
         * 跳转至详情
         */
        toInfo: function (e) {
            let that = this;
            that.$router.push({
                path: '/user/information',
                query: {member_id: e}
            });
        },

        /**
         * 查看详情
         * @param e
         */
        add: function (e) {
            let that = this;
            that.$router.push({
                path: '/user/information'
            });
        }
    }
}